//
//  PutQAViewController.m
//  Toyohu
//
//  Created by Heige on 16/5/11.
//  Copyright © 2016年 celia. All rights reserved.
//

#import "PutQAViewController.h"
#import <Masonry.h>
#import "GPAFNetworking3.h"
#import "QAStyleOneTableViewCell.h"
#import "myCommunityViewController.h"

#import "CYLTabBarControllerConfig.h"

#define WIDTH self.view.bounds.size.width
#define HEIGHT self.view.bounds.size.height

typedef void(^JumpBlock)(void);

@interface PutQAViewController ()<UITableViewDelegate,UITableViewDataSource>{
    UITableView *myTableView;
    UILabel *titleLabel;
}

@property (nonatomic, copy)JumpBlock jumpBlock;

@end

@implementation PutQAViewController

- (instancetype)initWithPageJump:(void(^)(void))jumpBlock
{
    self = [super init];
    if (self) {
        self.jumpBlock = jumpBlock;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self CreateNav];
    [self CreateTableView];
    
}

-(void)CreateNav
{
    UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 64)];
    navView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:navView];
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeSystem];
    backButton.frame = CGRectMake(0, 5, 62, 64);
    [backButton addTarget:self action:@selector(backPreviousPage) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backButton];
    
    UIImageView *backImage = [[UIImageView alloc] init];
    backImage.image = [UIImage imageNamed:@"return-gray@2x"];
    backImage.bounds = CGRectMake(0, 0, 12, 20);
    backImage.center = backButton.center;
    [backButton addSubview:backImage];
    
    UIButton*shareButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [shareButton setBackgroundImage:[UIImage imageNamed:@"share@2x"] forState:UIControlStateNormal];
    [navView addSubview:shareButton];
    [shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(navView.mas_trailing).offset(-20);
        make.width.equalTo(@(18));
        make.height.equalTo(@(18));
        make.centerY.equalTo(navView.mas_centerY).offset(10);
    }];
    
    titleLabel  = [[UILabel alloc]init];
    titleLabel.text = @"0个回答";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [navView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(navView.mas_centerY).offset(10);
        make.centerX.equalTo(navView);
        make.width.equalTo(@(100));
        make.height.equalTo(@(30));
    }];
    
}

-(void)CreateTableView
{
    myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT-64) style:UITableViewStylePlain];
    myTableView.delegate = self;
    myTableView.dataSource = self;
    [myTableView registerNib:[UINib nibWithNibName:@"QAStyleOneTableViewCell" bundle:nil] forCellReuseIdentifier:@"commentAns"];
    myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    myTableView.showsVerticalScrollIndicator = NO;
    
    [self.view addSubview:myTableView];
}

-(void)backPreviousPage
{
    //[self.navigationController popViewControllerAnimated:YES];
    [self dismissViewControllerAnimated:YES completion:nil];
    if (self.jumpBlock) {
        self.jumpBlock();

    }
//    myCommunityViewController *VC = [[myCommunityViewController alloc]init];
//    [self.navigationController pushViewController:VC animated:YES];
    
   //[self dismissViewControllerAnimated:YES completion:nil];
   // [self dismissViewControllerAnimated:YES completion:^{
        
   //     [self dismissViewControllerAnimated:YES completion:nil];
  //  }];
    
//
// myCommunityViewController *VC = [[myCommunityViewController alloc]init];
//   [self presentViewController:VC animated:YES completion:^{
//       
//      // [VC setHidesBottomBarWhenPushed:NO];
//    }];
   // [self.navigationController popViewControllerAnimated:YES];

    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        QAStyleOneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commentAns"];
        if (!cell) {
            cell = (QAStyleOneTableViewCell *)[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier: @"commentAns"];
        }
        return cell;
    }
    return nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
